import com.hll.spring_book.service.log.LogService;
import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.net.URL;
import java.nio.file.Paths;

@RunWith(SpringRunner.class)
/*测试swagger生成文档的前提条件，如果运行成功就行，当然是项目启动后，在运行该测试*/
public class test {
  @Resource private LogService logService;

  @Test
  public void generateAsciiDocs() throws Exception {
    // 输出Ascii格式
    Swagger2MarkupConfig config =
        new Swagger2MarkupConfigBuilder()
            .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
            .withOutputLanguage(Language.ZH)
            .withPathsGroupedBy(GroupBy.TAGS)
            .withGeneratedExamples()
            .withoutInlineSchema()
            .build();

    Swagger2MarkupConverter.from(new URL("http://localhost:8081/v2/api-docs"))
        .withConfig(config)
        .build()
        .toFolder(Paths.get("src/docs/asciidoc/generated"));
  }
}
